util: Add bit manipulation functions getbit and setbit.
authoroliskoli <oliskoli>
Mon, 23 Jun 2008 18:58:11 +0000 (18:58 +0000)
committeroliskoli <oliskoli>
Mon, 23 Jun 2008 18:58:11 +0000 (18:58 +0000)
defs.h
util.c

diff --git a/defs.h b/defs.h
index 40b487eefbf0c5ad81fbafc14ccb4bf41becf941..701259239f8168fa379916f61e72994f5e65e8d7 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -930,6 +930,11 @@ typedef enum {
 #define DATUM_OSGB36   86
 #define DATUM_WGS84    118
 
+/* bit manipulation functions (util.c) */
+
+char getbit(const void *buf, const gbuint32 nr);
+void setbit(void *buf, const gbuint32 nr);
+
 /*
  *  From parse.c
  */
diff --git a/util.c b/util.c
index 41286af81e57923934dc299ea5a797b82e0bb4eb..58600aff2f22eb5ca919ac2ac365f37646aebe79 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1736,3 +1736,25 @@ char *get_filename(const char *fname)
        
        return (res == NULL) ? (char *) fname : ++res;
 }
+
+/* bit manipulation functions */
+
+/*
+ * setbit: Set bit number [nr] of buffer [buf]
+ */
+void setbit(void *buf, const gbuint32 nr)
+{
+       unsigned char *bytes = buf;
+       bytes[nr / 8] |= (1 << (nr % 8));
+}
+
+/*
+ * setbit: Get state of bit number [nr] of buffer [buf]
+ */
+char getbit(const void *buf, const gbuint32 nr)
+{
+       const unsigned char *bytes = buf;
+       return (bytes[nr / 8] & (1 << (nr % 8)));
+       
+}
+